/**
 * 
 */
package com.module.osr.ui.stormbringer.charviewer.widgets;

import com.dalonedrau.jogl.opengl.sprite.BasicSpriteObject;
import com.dalonedrau.jogl.opengl.sprite.SpriteBase;
import com.dalonedrau.jogl.opengl.sprite.SpriteImageObject;
import com.dalonedrau.jogl.opengl.sprite.SpriteImageObjectFactory;
import com.dalonedrau.jogl.opengl.ui.Label;
import com.dalonedrau.jogl.opengl.ui.UIFactory;
import com.dalonedrau.jogl.opengl.ui.panel.LandscapePagePanel;
import com.dalonedrau.jogl.opengl.ui.panel.Panel;
import com.dalonedrau.pool.PooledStringBuilder;
import com.dalonedrau.pool.StringBuilderPool;
import com.module.osr.stormbringer.bus.SBCharacter;
import com.module.stormbringer.globals.Globals;
import com.module.stormbringer.globals.Globals;
import com.rpg.base.RPGConsts;

/**
 * The name panel widget, displaying the player's name, gender, race, and
 * profession. The panel is 428px wide by 19px high/
 * @author Donald
 */
public final class NamePanel extends LandscapePagePanel {
	/** the profession label. */
	private Label		lblClass;
	/** the gender label. */
	private Label		lblGender;
	/** the name label. */
	private Label		lblName;
	/** the race label. */
	private Label		lblNationiality;
	/** the sprite for the "female" icon. */
	private SpriteBase	sbFemale;
	/** the sprite for the "male" icon. */
	private SpriteBase	sbMale;
	/** the sprite for the "no gender" icon. */
	private SpriteBase	sbNone;
	/**
	 * Creates a new instance of {@link NamePanel}.
	 * @throws Exception if an error occurs
	 */
	public NamePanel() throws Exception {
		super(Panel.LANDSCAPE_CENTER);
		// GENDER - 10px x 18px
		sbMale = new BasicSpriteObject();
		SpriteImageObject img =
				SpriteImageObjectFactory.getInstance().getImageByName(
						"gender_male");
		sbMale.setImageRefId(img.getRefId());
		sbMale.setWidth(img.getWidth());
		sbMale.setHeight(img.getHeight());

		sbFemale = new BasicSpriteObject();
		img = SpriteImageObjectFactory.getInstance().getImageByName(
						"gender_female");
		sbFemale.setImageRefId(img.getRefId());
		sbFemale.setWidth(img.getWidth());
		sbFemale.setHeight(img.getHeight());

		sbNone = new BasicSpriteObject();
		img = SpriteImageObjectFactory.getInstance().getImageByName(
						"gender_none");
		sbNone.setImageRefId(img.getRefId());
		sbNone.setWidth(img.getWidth());
		sbNone.setHeight(img.getHeight());
		img = null;
		lblGender = new Label(sbNone);
		super.addChild(lblGender);
		// 2px spacer
		super.addChild(UIFactory.getInstance().getSpacer(2, 1));
		// NAME - 100px x 19px
		lblName = UIFactory.getInstance().getStandardH1Label("");
		lblName.setMinimumSize(100, 19);
		super.addChild(lblName);
		// 8px spacer
		super.addChild(UIFactory.getInstance().getSpacer(8, 1));
		// NATIONALITY - 150px x 19px
		lblNationiality = UIFactory.getInstance().getStandardH1Label("");
		lblNationiality.setMinimumSize(150, 19);
		lblNationiality.setTooltipText("");
		super.addChild(lblNationiality);
		// 8px spacer
		super.addChild(UIFactory.getInstance().getSpacer(8, 1));
		// CLASS - 150px x 19px
		lblClass = UIFactory.getInstance().getStandardH1Label("");
		lblClass.setMinimumSize(150, 19);
		lblClass.setTooltipText("");
		super.addChild(lblClass);
	}
	/**
	 * Updates the view.
	 * @param pc the {@link SBCharacter} being viewed
	 */
	public void update(final SBCharacter pc) {
		PooledStringBuilder sb =
				StringBuilderPool.getInstance().getStringBuilder();
		// NAME
		sb.append(pc.getName());
		lblName.setText(sb.toString());
		sb.setLength(0);
		// GENDER
		if (pc.getGender() >= 0) {
			if (pc.getGender() == RPGConsts.GENDER_MALE) {
				lblGender.setSprite(sbMale);
			} else {
				lblGender.setSprite(sbFemale);
			}
		} else {
			lblGender.setSprite(sbNone);
		}
		// NATIONALITY
		if (pc.getRace() >= 0) {
			lblNationiality.setText(Globals.RACE_TITLES[pc.getRace()]);
			lblNationiality.setTooltipText(
					Globals.RACE_DESCRIPTIONS[pc.getRace()]);
		} else {
			lblNationiality.setText("");
			lblNationiality.setTooltipText("");
		}
		// CLASS
		if (pc.getProfession() >= 0) {
			lblClass.setText(Globals.CLASS_TITLES[pc.getProfession()]);
			lblClass.setTooltipText("");
		} else {
			lblClass.setText("");
			lblClass.setTooltipText("");
		}
		sb.returnToPool();
	}
}
